package com.wel.onlineshopping.controller;

import com.wel.onlineshopping.model.Cart;
import com.wel.onlineshopping.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @GetMapping
    public List<Cart> getAllCartItems() {
        return cartService.getAllCartItems();
    }

    @PostMapping("/add")
    public Cart addProductToCart(@RequestParam Long productId, @RequestParam int quantity) {
        return cartService.addProductToCart(productId, quantity);
    }

    @PutMapping("/update/{cartItemId}")
    public Cart updateCartItem(@PathVariable Long cartItemId, @RequestParam int quantity) {
        return cartService.updateCartItem(cartItemId, quantity);
    }

    @DeleteMapping("/remove/{cartItemId}")
    public void removeCartItem(@PathVariable Long cartItemId) {
        cartService.removeCartItem(cartItemId);
    }
}

